package net.sf.rose.file.excel.poi.message;

import net.sf.rose.jdbc.bean.annotation.Column;
import net.sf.rose.jdbc.bean.annotation.Table;
import net.sf.rose.jdbc.bean.annotation.Type;

/**
 * 行执行消息
 */
@Table(name = "SYS_EXCEL_RECORD", description = "Excel导入行执行消息结果")
public class RowMessage {

    @Column(name = "RECORD_ID", pk = true, type = Type.定长文本, description = "编号", size = 32, policy = "UUID")
    private String recordID = null;

    @Column(name = "MESSAGE_ID", type = Type.定长文本, description = "编号", size = 32)
    private String messageID = null;

    /** 行号 */
    @Column(name = "ROW_INDEX", type = Type.数字整型, description = "行号")
    private int row = 0;

    /** 1：成功；2：有错误； */
    @Column(name = "SUCCESS", type = Type.数字整型, description = "执行结果")
    private int success = 1;

    @Column(name = "MESSAGE", type = Type.变长文本, description = "失败详情", size = 200)
    private String message = null;

    /**
     * 添加一条有错误执行记录
     * 
     * @param message
     */
    public void addMessage(CellMessage message) {
        if (this.message == null) {
            this.message = message.toString();
        } else {
            this.message = this.message + '\n' + message.toString();
        }
        this.success = 2;
    }

    public int getRow() {
        return row;
    }

    public String getRecordID() {
        return recordID;
    }

    public void setRecordID(String recordID) {
        this.recordID = recordID;
    }

    public String getMessageID() {
        return messageID;
    }

    public void setMessageID(String messageID) {
        this.messageID = messageID;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public boolean isSuccess() {
        return success == 1;
    }

    public int getSuccess() {
        return success;
    }

    public void setSuccess(int success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("row:").append(row).append(';');
        sb.append("success:").append(success).append('\n');
        sb.append("message:").append(message).append('\n');
        return sb.toString();
    }

}
